<%--
  百度地图选取经纬度页面
  User: JiangXueLi
  Date: 2017/3/28
  Time: 16:25
  返回页面坐标经纬度.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<style type="text/css">
    html{height:100%}
    body{height:100%;margin:0px;padding:0px}
    #container{height: 500px;width:100%;}
</style>
<div class="portlet light">
    <div class="portlet-body form">
        <input type="hidden" id="lng">
        <input type="hidden" id="lat">
        <input type="hidden" id="address">

        <div id="container"></div>
    </div>
</div>
<script type="text/javascript">

    var map = new BMap.Map("container"); // 创建地图实例// 初始化地图，设置中心点坐标和地图级别
    map.enableScrollWheelZoom(true);
    map.centerAndZoom(new BMap.Point(116.404, 39.915),5);          // 初始化地图,用城市名设置地图中心点
    function showInfo(e){
        map.clearOverlays();
        var pt = new BMap.Point(e.point.lng, e.point.lat);
        var marker2 = new BMap.Marker(pt);  // 创建标注
        map.addOverlay(marker2);//标注加载到地图
        var geoc = new BMap.Geocoder();
        var pt1 = e.point;
        geoc.getLocation(pt1, function(rs){
            var addComp = rs.addressComponents;
            $("#address").val(addComp.street+addComp.streetNumber);//经纬度填充到input

/*
            alert(addComp.province + ", " + addComp.city + ", " + addComp.district + ", " + addComp.street + ", " + addComp.streetNumber);
*/
        });
        $("#lng").val(e.point.lng);//经纬度填充到input
        $("#lat").val(e.point.lat);
    }
    map.addEventListener("click", showInfo);
</script>

